package main

import "fmt"

func modifyString() {
	str := "abc"
	str = "def"
	/**
	编译报如下错误
	cannot assign to str[0] (neither addressable nor a map index expression)
	str[0] = "g"
	*/
	fmt.Println("str: ", str)
}

func visitString() {
	str := "abcdefg"
	size := len(str)

	for i := 0; i < size; i++ {
		fmt.Printf("i: %d, v: %d\n", i, str[i])
	}

	fmt.Println()

	for i, v := range str {
		fmt.Printf("i: %d, v: %d\n", i, v)
	}
}

func stringAddress() {
	str := "abcdefg"
	/**
	编译报如下错误
	invalid operation: cannot take address of str[0] (value of type byte)
	fmt.Println(&str[0])
	*/
	fmt.Println(str[1])
}

func sliceString() {
	str := "abcdefg"
	s1 := str[:]
	s2 := str[1:]
	s3 := str[:3]
	s4 := str[1:2]
	fmt.Println(len(str), str, s1, s2, s3, s4)
}

func addString() {
	a := "ch"
	b := "ina"
	c := a + b
	fmt.Println(c)
}

// func main() {
// 	modifyString()
// 	visitString()
// 	stringAddress()
// 	sliceString()
// 	addString()
// }